package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目Controller类
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = {"护理项目管理"})
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页条件查询护理项目
     *
     * @param name    项目名称（可选）
     * @param pageNum 当前页码，默认1
     * @param pageSize 每页大小，默认10
     * @param status  项目状态（可选）
     * @return 分页响应结果
     */
    @GetMapping
    @ApiOperation(value = "分页条件查询护理项目", notes = "根据项目名称和状态分页查询护理项目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "项目名称（可选）", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码，默认1", defaultValue = "1", required = false, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小，默认10", defaultValue = "10", required = false, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "项目状态（可选）", required = false, dataType = "Integer", paramType = "query")
    })
    public ResponseResult<PageResponse<NursingProjectVo>> list(
            String name,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            Integer status) {
        logger.info("分页条件查询: {},{},{},{}", name, pageNum, pageSize, status);
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.list(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult save(@RequestBody NursingProjectDto nursingProjectDto) {
        logger.info("新增护理项目: {}",nursingProjectDto);
        nursingProjectService.save(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查询护理
     * @param id
     * @return
     */
    @ApiOperation("根据ID查询护理")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id) {
        logger.info("根据ID查询护理: {}",id);
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    /**
     * 修改护理
     * @param nursingProjectDto
     * @return
     */
    @ApiOperation("修改护理")
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        logger.info("修改护理: {}",nursingProjectDto);
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @ApiOperation("删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        logger.info("删除护理项目: {}",id);
        nursingProjectService.delete(id);
        return success();
    }

    /**
     * 启用禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @ApiOperation("启用禁用护理项目")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult startOrStop(@PathVariable Long id, @PathVariable Integer status) {
        logger.info("启用禁用护理项目: {},{}",id,status);
        nursingProjectService.startOrStop(id,status);
        return success();
    }

    /**
     * 查询所有护理项目
     * @return
     */
    @ApiOperation("查询所有护理项目")
    @GetMapping("/all")
    public ResponseResult<NursingProjectVo> getAll() {
        logger.info("查询所有护理项目");
        List<NursingProjectVo> nursingProjectVoList = nursingProjectService.getAll();
        return success(nursingProjectVoList);
    }
}